<?php
namespace app\admin\controller;

class Statistics extends Admin{
	public function __construct(){
        parent::__construct();
        $this->model = "Statistics";
        $this->assign("model",$this->model);
    }
    public function index(){
    
    	// $this->assign('wheredata', 'kind=1&typeid=3');
         
        $this->assign("kind", 1);
        $this->assign("typeid", 4);
    	return $this->fetch();
    }
    public function index_market(){
    	// $this->assign('wheredata', 'kind=2&typeid=3');
        $this->assign("kind", 2);
        $this->assign("typeid", 4);
    	return $this->fetch();
    }
    public function get_where_map(){
        $kind = input('param.kind');
        $typeid = input('param.typeid');
        $keywords = input('param.keywords');
        $whereDatas = [];
        if ($kind) {
            $whereDatas['kind'] = $kind;
        }
        if ($typeid) {
            $whereDatas['typeid'] = $typeid;
        }
        $where = [];
        if ($keywords) {
            $where['realname'] = ['like', "%$keywords%"];
        }
        if ($this->uinfo['roleid'] != 1 && $this->uinfo['roleid'] != 4) {
            $where['roleid'] = 9;
            $userids = model('AdminUser')->where('dealerid', $this->uinfo['userid'])->where($where)->column('userid');
            $whereDatas['userid'] = ['in', $userids];
        }else{
            $where['roleid'] = $whereDatas['kind'] == 1 ? 9 : 8;
            $userids = model('AdminUser')->where($where)->column('userid');
            // $userids = [];
            // foreach ($list as $v) {
            //     $userids[] = $v['userid'];
            // }
            $whereDatas['userid'] = ['in', $userids];
        }
        return $whereDatas;
    }
}	